package com.example.blog.controller;


import com.example.blog.service.ArticleService;
import com.example.blog.vo.Result;
import com.example.blog.vo.params.ArticleParam;
import com.example.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页文章列表
     * @param pageParams
     * @return
     */
    @PostMapping()
    public Result listArticle(@RequestHeader("Authorization") String token, @RequestBody PageParams pageParams) {
        return articleService.listArticle(token, pageParams);
    }

    @PostMapping({"/view/{id}"})
    public Result findArticleById(@RequestHeader("Authorization") String token, @PathVariable("id") Long articleId) {
        return this.articleService.findArticleById(token, articleId);
    }

    @PostMapping({"likes/{id}"})
    public Result likesAdd(@RequestHeader("Authorization") String token, @PathVariable("id") Long articleId) {
        return this.articleService.likesAdd(token, articleId);
    }

    @PostMapping({"collection/{articleId}"})
    public Result addCollection(@RequestHeader("Authorization") String token,@PathVariable Long articleId) {
        return this.articleService.addCollection(token, articleId);
    }

    @PostMapping({"publish"})
    public Result publish(@RequestBody ArticleParam articleParam) {
        return this.articleService.publish(articleParam);
    }

    @PostMapping({"change"})
    public Result updateArticle(@RequestBody ArticleParam articleParam) {
        return this.articleService.change(articleParam);
    }

}
